/* Copyright 2007 Gearbox Software - http://www.gearboxsoft.com
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 
     http:www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.*/
namespace GearBlog.Web.Models
{
	using System;
	using Castle.ActiveRecord;
	using Castle.Components.Validator;

	public enum CommentStatus
	{
		Moderation,
		Posted
	} ;
	[ActiveRecord]
	public class Comment:ExtendedActiveRecordBase<Comment>
	{
		private Post _post;
		private string _authorName;
		private string _content;
		private DateTime _createdAt;
		private CommentStatus _status;


		public Comment()
		{
			_createdAt = DateTime.Now;
			CommentSetup();
		}

		//Routine which does strategy object setup base on various parameters
		private void CommentSetup()
		{
			if (Setting.Get().ModerateComments)
				_status = CommentStatus.Moderation;
			else
				_status = CommentStatus.Posted;

		}

		[BelongsTo]
		public Post Post
		{
			get { return _post; }
			set { _post = value; }
		}

		[Property(Length = 50, NotNull = true), ValidateNonEmpty("Author name cannot be empty.")]
		public string AuthorName
		{
			get { return _authorName; }
			set { _authorName = value; }
		}

		[Property(Length = 100000, NotNull = true), ValidateNonEmpty]
		public string Content
		{
			get { return _content; }
			set { _content = value; }
		}

		[Property(NotNull=true)]
		public DateTime CreatedAt
		{
			get { return _createdAt; }
			set { _createdAt = value; }
		}

		[Property(NotNull=true)]
		public CommentStatus Status
		{
			get { return _status; }
			set { _status = value; }
		}

	}
}
